PLUGIN.Help = [[Look at a prop and enter this command
It will add the prop to your selected list for you to later manipulate]]

-- every plugin MUST contain an Initialize method, here is where you initialize tables and data
function PLUGIN:Initialize() 
	ecs.OldColours = {}
end
//if CLIENT then return end

function PLUGIN.RemoveSelectionOnRemovedEnt( ent )
	for k , ply in pairs(player.GetAll()) do
		if ecs.Selections[ply] then
			local key = table.KeyFromValue( ecs.Selections[ply] , ent )
			if key then
				table.remove( ecs.Selections[ply] , key )
			end
			ecs.OldColours[ent] = nil
		end
	end
end
hook.Add("EntityRemoved","ECS_selectioncleaner",PLUGIN.RemoveSelectionOnRemovedEnt)

function PLUGIN:SelectedColor( ent )
	ecs.OldColours[ent] = Color(ent:GetColor())
	ent:SetColor(Color(200,30,30,140))
end

function PLUGIN:RevertColor( ent )
	ent:SetColor(ecs.OldColours[ent])
	ecs.OldColours[ent] = nil
end

function PLUGIN:RevertColors( ents )
	for k , ent in pairs( ents ) do
		if ecs.OldColours[ent] then
			
			ent:SetColor(ecs.OldColours[ent])
			ecs.OldColours[ent] = nil
		end
	end
end

function PLUGIN:Select(ply , args)
	if CLIENT then return end
	local ent = ply:GetEyeTraceNoCursor().Entity

	if not IsValid(ent) or ent:IsPlayer() or ent:IsWorld() then return end
	if not self:AddSelection( ply , ent ) then return end

	self:SelectedColor(ent)
end
PLUGIN:AddServerCommand( "select" , PLUGIN.Select )
-- PLUGIN:AddServerCommand takes 3 arguments, command name which has "e_" appended to it, the callback function
-- and the autocomplete arg, which can be a string , a table or a function

function PLUGIN:SelectSphere( ply , args )
	if CLIENT then return end
	local pos = ply:GetEyeTraceNoCursor().HitPos
	local radius = tonumber( args[1] )
	local canselect = {}
	for key , ent in pairs(ents.FindInSphere( pos , radius )) do
		if ecs.CanManipulate( ply , ent ) then
			canselect[ #canselect + 1 ] = ent
			self:SelectedColor(ent)
		end
	end

	self:AddSelections( ply , canselect )
end
PLUGIN:AddServerCommand( "selectsphere" , PLUGIN.SelectSphere )

function PLUGIN:Deselect(ply , args)
	if CLIENT then return end
	local ent = ply:GetEyeTraceNoCursor().Entity
	if not self:RemoveSelection( ply , ent ) then return end

	self:RevertColor( ent )
end
PLUGIN:AddServerCommand( "deselect" , PLUGIN.Deselect )

function PLUGIN:DeselectAll(ply , args)
	if CLIENT then return end	
	self:RevertColors( self:GetSelections( ply ) )
	self:RemoveAllSelections( ply )
end
PLUGIN:AddServerCommand( "deselectall" , PLUGIN.DeselectAll )

